1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module pango.PgMatrix;
26 
27 private import glib.MemorySlice;
28 private import gobject.ObjectG;
29 private import linker.Loader;
30 private import pango.c.functions;
31 public  import pango.c.types;
32 
33 
34 /**
35  * A `PangoMatrix` specifies a transformation between user-space
36  * and device coordinates.
37  * 
38  * The transformation is given by
39  * 
40  * ```
41  * x_device = x_user * matrix->xx + y_user * matrix->xy + matrix->x0;
42  * y_device = x_user * matrix->yx + y_user * matrix->yy + matrix->y0;
43  * ```
44  *
45  * Since: 1.6
46  */
47 public final class PgMatrix
48 {
49 	/** the main Gtk struct */
50 	protected PangoMatrix* pangoMatrix;
51 	protected bool ownedRef;
52 
53 	/** Get the main Gtk struct */
54 	public PangoMatrix* getPgMatrixStruct(bool transferOwnership = false)
55 	{
56 		if (transferOwnership)
57 			ownedRef = false;
58 		return pangoMatrix;
59 	}
60 
61 	/** the main Gtk struct as a void* */
62 	protected void* getStruct()
63 	{
64 		return cast(void*)pangoMatrix;
65 	}
66 
67 	/**
68 	 * Sets our main struct and passes it to the parent class.
69 	 */
70 	public this (PangoMatrix* pangoMatrix, bool ownedRef = false)
71 	{
72 		this.pangoMatrix = pangoMatrix;
73 		this.ownedRef = ownedRef;
74 	}
75 
76 	~this ()
77 	{
78 		if ( Linker.isLoaded(LIBRARY_PANGO[0]) && ownedRef )
79 			pango_matrix_free(pangoMatrix);
80 	}
81 
82 
83 	/**
84 	 * 1st component of the transformation matrix
85 	 */
86 	public @property double xx()
87 	{
88 		return pangoMatrix.xx;
89 	}
90 
91 	/** Ditto */
92 	public @property void xx(double value)
93 	{
94 		pangoMatrix.xx = value;
95 	}
96 
97 	/**
98 	 * 2nd component of the transformation matrix
99 	 */
100 	public @property double xy()
101 	{
102 		return pangoMatrix.xy;
103 	}
104 
105 	/** Ditto */
106 	public @property void xy(double value)
107 	{
108 		pangoMatrix.xy = value;
109 	}
110 
111 	/**
112 	 * 3rd component of the transformation matrix
113 	 */
114 	public @property double yx()
115 	{
116 		return pangoMatrix.yx;
117 	}
118 
119 	/** Ditto */
120 	public @property void yx(double value)
121 	{
122 		pangoMatrix.yx = value;
123 	}
124 
125 	/**
126 	 * 4th component of the transformation matrix
127 	 */
128 	public @property double yy()
129 	{
130 		return pangoMatrix.yy;
131 	}
132 
133 	/** Ditto */
134 	public @property void yy(double value)
135 	{
136 		pangoMatrix.yy = value;
137 	}
138 
139 	/**
140 	 * x translation
141 	 */
142 	public @property double x0()
143 	{
144 		return pangoMatrix.x0;
145 	}
146 
147 	/** Ditto */
148 	public @property void x0(double value)
149 	{
150 		pangoMatrix.x0 = value;
151 	}
152 
153 	/**
154 	 * y translation
155 	 */
156 	public @property double y0()
157 	{
158 		return pangoMatrix.y0;
159 	}
160 
161 	/** Ditto */
162 	public @property void y0(double value)
163 	{
164 		pangoMatrix.y0 = value;
165 	}
166 
167 	/** */
168 	public static GType getType()
169 	{
170 		return pango_matrix_get_type();
171 	}
172 
173 	/**
174 	 * Changes the transformation represented by @matrix to be the
175 	 * transformation given by first applying transformation
176 	 * given by @new_matrix then applying the original transformation.
177 	 *
178 	 * Params:
179 	 *     newMatrix = a `PangoMatrix`
180 	 *
181 	 * Since: 1.6
182 	 */
183 	public void concat(PgMatrix newMatrix)
184 	{
185 		pango_matrix_concat(pangoMatrix, (newMatrix is null) ? null : newMatrix.getPgMatrixStruct());
186 	}
187 
188 	/**
189 	 * Copies a `PangoMatrix`.
190 	 *
191 	 * Returns: the newly allocated `PangoMatrix`
192 	 *
193 	 * Since: 1.6
194 	 */
195 	public PgMatrix copy()
196 	{
197 		auto __p = pango_matrix_copy(pangoMatrix);
198 
199 		if(__p is null)
200 		{
201 			return null;
202 		}
203 
204 		return ObjectG.getDObject!(PgMatrix)(cast(PangoMatrix*) __p, true);
205 	}
206 
207 	/**
208 	 * Free a `PangoMatrix`.
209 	 *
210 	 * Since: 1.6
211 	 */
212 	public void free()
213 	{
214 		pango_matrix_free(pangoMatrix);
215 		ownedRef = false;
216 	}
217 
218 	/**
219 	 * Returns the scale factor of a matrix on the height of the font.
220 	 *
221 	 * That is, the scale factor in the direction perpendicular to the
222 	 * vector that the X coordinate is mapped to.  If the scale in the X
223 	 * coordinate is needed as well, use [method@Pango.Matrix.get_font_scale_factors].
224 	 *
225 	 * Returns: the scale factor of @matrix on the height of the font,
226 	 *     or 1.0 if @matrix is %NULL.
227 	 *
228 	 * Since: 1.12
229 	 */
230 	public double getFontScaleFactor()
231 	{
232 		return pango_matrix_get_font_scale_factor(pangoMatrix);
233 	}
234 
235 	/**
236 	 * Calculates the scale factor of a matrix on the width and height of the font.
237 	 *
238 	 * That is, @xscale is the scale factor in the direction of the X coordinate,
239 	 * and @yscale is the scale factor in the direction perpendicular to the
240 	 * vector that the X coordinate is mapped to.
241 	 *
242 	 * Note that output numbers will always be non-negative.
243 	 *
244 	 * Params:
245 	 *     xscale = output scale factor in the x direction
246 	 *     yscale = output scale factor perpendicular to the x direction
247 	 *
248 	 * Since: 1.38
249 	 */
250 	public void getFontScaleFactors(out double xscale, out double yscale)
251 	{
252 		pango_matrix_get_font_scale_factors(pangoMatrix, &xscale, &yscale);
253 	}
254 
255 	/**
256 	 * Gets the slant ratio of a matrix.
257 	 *
258 	 * For a simple shear matrix in the form:
259 	 *
260 	 * 1 λ
261 	 * 0 1
262 	 *
263 	 * this is simply λ.
264 	 *
265 	 * Returns: the slant ratio of @matrix
266 	 *
267 	 * Since: 1.50
268 	 */
269 	public double getSlantRatio()
270 	{
271 		return pango_matrix_get_slant_ratio(pangoMatrix);
272 	}
273 
274 	/**
275 	 * Changes the transformation represented by @matrix to be the
276 	 * transformation given by first rotating by @degrees degrees
277 	 * counter-clockwise then applying the original transformation.
278 	 *
279 	 * Params:
280 	 *     degrees = degrees to rotate counter-clockwise
281 	 *
282 	 * Since: 1.6
283 	 */
284 	public void rotate(double degrees)
285 	{
286 		pango_matrix_rotate(pangoMatrix, degrees);
287 	}
288 
289 	/**
290 	 * Changes the transformation represented by @matrix to be the
291 	 * transformation given by first scaling by @sx in the X direction
292 	 * and @sy in the Y direction then applying the original
293 	 * transformation.
294 	 *
295 	 * Params:
296 	 *     scaleX = amount to scale by in X direction
297 	 *     scaleY = amount to scale by in Y direction
298 	 *
299 	 * Since: 1.6
300 	 */
301 	public void scale(double scaleX, double scaleY)
302 	{
303 		pango_matrix_scale(pangoMatrix, scaleX, scaleY);
304 	}
305 
306 	/**
307 	 * Transforms the distance vector (@dx,@dy) by @matrix.
308 	 *
309 	 * This is similar to [method@Pango.Matrix.transform_point],
310 	 * except that the translation components of the transformation
311 	 * are ignored. The calculation of the returned vector is as follows:
312 	 *
313 	 * ```
314 	 * dx2 = dx1 * xx + dy1 * xy;
315 	 * dy2 = dx1 * yx + dy1 * yy;
316 	 * ```
317 	 *
318 	 * Affine transformations are position invariant, so the same vector
319 	 * always transforms to the same vector. If (@x1,@y1) transforms
320 	 * to (@x2,@y2) then (@x1+@dx1,@y1+@dy1) will transform to
321 	 * (@x1+@dx2,@y1+@dy2) for all values of @x1 and @x2.
322 	 *
323 	 * Params:
324 	 *     dx = in/out X component of a distance vector
325 	 *     dy = in/out Y component of a distance vector
326 	 *
327 	 * Since: 1.16
328 	 */
329 	public void transformDistance(ref double dx, ref double dy)
330 	{
331 		pango_matrix_transform_distance(pangoMatrix, &dx, &dy);
332 	}
333 
334 	/**
335 	 * First transforms the @rect using @matrix, then calculates the bounding box
336 	 * of the transformed rectangle.
337 	 *
338 	 * This function is useful for example when you want to draw a rotated
339 	 * @PangoLayout to an image buffer, and want to know how large the image
340 	 * should be and how much you should shift the layout when rendering.
341 	 *
342 	 * For better accuracy, you should use [method@Pango.Matrix.transform_rectangle]
343 	 * on original rectangle in Pango units and convert to pixels afterward
344 	 * using [func@extents_to_pixels]'s first argument.
345 	 *
346 	 * Params:
347 	 *     rect = in/out bounding box in device units
348 	 *
349 	 * Since: 1.16
350 	 */
351 	public void transformPixelRectangle(ref PangoRectangle rect)
352 	{
353 		pango_matrix_transform_pixel_rectangle(pangoMatrix, &rect);
354 	}
355 
356 	/**
357 	 * Transforms the point (@x, @y) by @matrix.
358 	 *
359 	 * Params:
360 	 *     x = in/out X position
361 	 *     y = in/out Y position
362 	 *
363 	 * Since: 1.16
364 	 */
365 	public void transformPoint(ref double x, ref double y)
366 	{
367 		pango_matrix_transform_point(pangoMatrix, &x, &y);
368 	}
369 
370 	/**
371 	 * First transforms @rect using @matrix, then calculates the bounding box
372 	 * of the transformed rectangle.
373 	 *
374 	 * This function is useful for example when you want to draw a rotated
375 	 * @PangoLayout to an image buffer, and want to know how large the image
376 	 * should be and how much you should shift the layout when rendering.
377 	 *
378 	 * If you have a rectangle in device units (pixels), use
379 	 * [method@Pango.Matrix.transform_pixel_rectangle].
380 	 *
381 	 * If you have the rectangle in Pango units and want to convert to
382 	 * transformed pixel bounding box, it is more accurate to transform it first
383 	 * (using this function) and pass the result to pango_extents_to_pixels(),
384 	 * first argument, for an inclusive rounded rectangle.
385 	 * However, there are valid reasons that you may want to convert
386 	 * to pixels first and then transform, for example when the transformed
387 	 * coordinates may overflow in Pango units (large matrix translation for
388 	 * example).
389 	 *
390 	 * Params:
391 	 *     rect = in/out bounding box in Pango units
392 	 *
393 	 * Since: 1.16
394 	 */
395 	public void transformRectangle(ref PangoRectangle rect)
396 	{
397 		pango_matrix_transform_rectangle(pangoMatrix, &rect);
398 	}
399 
400 	/**
401 	 * Changes the transformation represented by @matrix to be the
402 	 * transformation given by first translating by (@tx, @ty)
403 	 * then applying the original transformation.
404 	 *
405 	 * Params:
406 	 *     tx = amount to translate in the X direction
407 	 *     ty = amount to translate in the Y direction
408 	 *
409 	 * Since: 1.6
410 	 */
411 	public void translate(double tx, double ty)
412 	{
413 		pango_matrix_translate(pangoMatrix, tx, ty);
414 	}
415 
416 	/**
417 	 * Converts extents from Pango units to device units.
418 	 *
419 	 * The conversion is done by dividing by the %PANGO_SCALE factor and
420 	 * performing rounding.
421 	 *
422 	 * The @inclusive rectangle is converted by flooring the x/y coordinates
423 	 * and extending width/height, such that the final rectangle completely
424 	 * includes the original rectangle.
425 	 *
426 	 * The @nearest rectangle is converted by rounding the coordinates
427 	 * of the rectangle to the nearest device unit (pixel).
428 	 *
429 	 * The rule to which argument to use is: if you want the resulting device-space
430 	 * rectangle to completely contain the original rectangle, pass it in as
431 	 * @inclusive. If you want two touching-but-not-overlapping rectangles stay
432 	 * touching-but-not-overlapping after rounding to device units, pass them in
433 	 * as @nearest.
434 	 *
435 	 * Params:
436 	 *     inclusive = rectangle to round to pixels inclusively
437 	 *     nearest = rectangle to round to nearest pixels
438 	 *
439 	 * Since: 1.16
440 	 */
441 	public static void extentsToPixels(PangoRectangle* inclusive, PangoRectangle* nearest)
442 	{
443 		pango_extents_to_pixels(inclusive, nearest);
444 	}
445 
446 	/**
447 	 * Converts a floating-point number to Pango units.
448 	 *
449 	 * The conversion is done by multiplying @d by %PANGO_SCALE and
450 	 * rounding the result to nearest integer.
451 	 *
452 	 * Params:
453 	 *     d = double floating-point value
454 	 *
455 	 * Returns: the value in Pango units.
456 	 *
457 	 * Since: 1.16
458 	 */
459 	public static int unitsFromDouble(double d)
460 	{
461 		return pango_units_from_double(d);
462 	}
463 
464 	/**
465 	 * Converts a number in Pango units to floating-point.
466 	 *
467 	 * The conversion is done by dividing @i by %PANGO_SCALE.
468 	 *
469 	 * Params:
470 	 *     i = value in Pango units
471 	 *
472 	 * Returns: the double value.
473 	 *
474 	 * Since: 1.16
475 	 */
476 	public static double unitsToDouble(int i)
477 	{
478 		return pango_units_to_double(i);
479 	}
480 }